package IC.Lexer;

import java_cup.runtime.Symbol;

/**
 * Token represantation class
 * Saves all needed information about a token
 */
public class Token extends Symbol {
	
	/**
	 *  Make a token without a value field
	 * @param type symbol type
	 * @param line the line where the symbol resides
	 */
	public Token(int type, int line, int column) {
		super(type);
		super.value = new ExtToken(line+1, column+1, this);

	}
	
	
	/**
	 *  Make a token with a value field
	 * @param type symbol type
	 * @param value symbol value
	 * @param line the line where the symbol resides
	 */
	public Token(int type, Object value, int line, int column) {
		super(type);
		super.value = new ExtToken(line+1, column+1, value);
		
	}

	/**
	 * print the token, escape strings
	 */ 
	public String toString()
	{
		switch (sym) {
			case IC.Parser.sym.QUOTE:
				String escapedStr = value.toString()
						.replace("\\", "\\\\")
						.replace("\"", "\\\"")
						.replace("\n", "\\n")
						.replace("\t", "\\t");
				return "QUOTE (\""+escapedStr+"\") ";
			case IC.Parser.sym.INTEGER:
				return "INTEGER ("+value.toString()+")";
			case IC.Parser.sym.CLASS_ID:
				return "CLASS_ID ("+value.toString()+")";
			case IC.Parser.sym.ID:
				return "ID ("+value.toString()+")";
			case IC.Parser.sym.DIVIDE: return "DIVIDE";
			case IC.Parser.sym.LCBR: return "LCBR";
			case IC.Parser.sym.LTE: return "LTE";
			case IC.Parser.sym.SEMI: return "SEMI";
			case IC.Parser.sym.CONTINUE: return "CONTINUE";
			case IC.Parser.sym.INT: return "INT";
			case IC.Parser.sym.MINUS: return "MINUS";
			case IC.Parser.sym.STATIC: return "STATIC";
			case IC.Parser.sym.LT: return "LT";
			case IC.Parser.sym.LP: return "LP";
			case IC.Parser.sym.COMMA: return "COMMA";
			case IC.Parser.sym.CLASS: return "CLASS ";
			case IC.Parser.sym.RP: return "RP";
			case IC.Parser.sym.PLUS: return "PLUS";
			case IC.Parser.sym.MULTIPLY: return "MULTIPLY";
			case IC.Parser.sym.ASSIGN: return "ASSIGN";
			case IC.Parser.sym.IF: return "IF";
			case IC.Parser.sym.THIS: return "THIS";
			case IC.Parser.sym.DOT: return "DOT";
			case IC.Parser.sym.EOF: return "EOF";
			case IC.Parser.sym.BOOLEAN: return "BOOLEAN";
			case IC.Parser.sym.RETURN: return "RETURN";
			case IC.Parser.sym.RCBR: return "RCBR";
			case IC.Parser.sym.LB: return "LB";
			case IC.Parser.sym.LAND: return "LAND";
			case IC.Parser.sym.EQUAL: return "EQUAL";
			case IC.Parser.sym.TRUE: return "TRUE";
			case IC.Parser.sym.NEW: return "NEW";
			case IC.Parser.sym.error: return "error";
			case IC.Parser.sym.RB: return "RB ";
			case IC.Parser.sym.LOR: return "LOR";
			case IC.Parser.sym.NULL: return "NULL";
			case IC.Parser.sym.MOD: return "MOD";
			case IC.Parser.sym.BREAK: return "BREAK";
			case IC.Parser.sym.VOID: return "VOID";
			case IC.Parser.sym.GTE: return "GTE";
			case IC.Parser.sym.ELSE: return "ELSE";
			case IC.Parser.sym.WHILE: return "WHILE";
			case IC.Parser.sym.NEQUAL: return "NEQUAL";
			case IC.Parser.sym.EXTENDS: return "EXTENDS";
			case IC.Parser.sym.STRING: return "STRING";
			case IC.Parser.sym.LNEG: return "LNEG";
			case IC.Parser.sym.FALSE: return "FALSE";
			case IC.Parser.sym.GT: return "GT";
			case IC.Parser.sym.LENGTH: return "LENGTH";				
		}
		return "";
	}

	public boolean isEOF()
	{
		return (sym == IC.Parser.sym.EOF);
	}
	
	/**
	 * 
	 * @return the token line number
	 */
	public int getLine() {
		return (((ExtToken)super.value).getLine());
	}
	
	public int getColumn() {
		return (((ExtToken)super.value).getColumn());
	}
	
	public Object getValue() {
		return ((ExtToken)super.value).getValue();
	}

}
